package dtomap

import (
	"bufio"
	"os"
)

type SourceText struct {
	lines        []string
	curLineIndex int
}

func (s *SourceText) LoadLines(path string) error {
	file, err := os.Open(path)
	if err != nil {
		return err
	}

	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		s.lines = append(s.lines, scanner.Text())
	}
	return nil
}

func (s *SourceText) FirstLine() string {
	if len(s.lines) > 0 {
		line := s.lines[0]
		return line
	}

	return ""
}

func (s *SourceText) NextLine() bool {
	s.curLineIndex++

	if s.curLineIndex < len(s.lines) {
		return true
	}

	return false
}

func (s *SourceText) Line() string {
	return s.lines[s.curLineIndex]
}
